package org.opengauss.sqltranslator.dialect.mysql.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


public class SqlInstallTransformUtil {
    private static final Logger logger= LoggerFactory.getLogger(SqlInstallTransformUtil.class);
    private static final Map<String, String> sqlMap = new HashMap<>(){
        {
            put("information_schema.columns", "SELECT A.attname AS column_name, col_description(A.attrelid, A.attnum) AS column_comment FROM pg_class AS C, pg_attribute AS A WHERE A.attrelid = C.oid AND A.attnum > 0 and   A.atttypid != 0   and C.relname  ='%s';");
        }
    };
    public static String getSql(String sql){

        String res = null;
        Set<String> strings = sqlMap.keySet();
        for(String string : strings){
            if(sql.contains(string)){
                 String tableName = sql.substring(sql.lastIndexOf("=")+3,sql.lastIndexOf("'"));
                 res = String.format(sqlMap.get(string), tableName);
            }
        }
        return res;
    }

}
